#include<iostream>
using namespace std;
int f(char x){
    if('A'<=x&&x<='Z'){
        return x-'A'+1;
    }else return -(x-'a'+1);
}
int main(){
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        int y;
        char x;
        cin>>x>>y;
        int sum=y+f(x);
        cout<<sum<<endl;
    }
}